clapにおける サブコマンド
from task-stash の 開発ログ
clapにおけるサブコマンド
なるほど、enumでサブコマンドの種類を列挙、引数でそのサブコマンドを列挙するって感じか
code:rs
use clap::{Args, Parser, Subcommand};
#derive(Subcommand)
enum Commands {
Push(PushArgs),
}
#derive(Args)
struct PushArgs {
title: String,
}
#derive(Parser)
#command(author, version, about, long_about = None)
struct CLI {
#command(subcommand)
command: Commands,
}
fn main() {
let cli = CLI::parse();
match &cli.command {
Commands::Push(args) => {
println!("{}", args.title)
}
}
}